/**
 * @(#)Main.java 2011-8-24 Copyright 2011 it.kedacom.com, Inc. All rights
 *               reserved.
 */

package com.kedacom.xmpp.demo.oneserver.chat;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.packet.MultipleAddresses;


 /**
  * 发送组播消息
  * @author 何霄刚  
  * @date 2011-12-28
  */
 
public class User1Multicast {

	/**
	 * (用一句话描述方法的主要功能)
	 * @param args
	 * @throws XMPPException
	 * @throws InterruptedException
	 */

	public static void main(String[] args) throws XMPPException, InterruptedException {
		String SERVER = "ts.local", USER = "admin", PASS = "888";

		// 登录
		XMPPConnection conn = new XMPPConnection(SERVER);
		conn.connect();
		conn.login(USER, PASS, null);
		System.out.println("admin已登录!");
		
		conn.addPacketListener(new PacketListener(){

			@Override
			public void processPacket(Packet packet) {
				System.out.println("<--	"+packet.toXML());
			}
			
		}, null);
		conn.addPacketSendingListener(new PacketListener(){

			@Override
			public void processPacket(Packet packet) {
				System.out.println("-->	"+packet.toXML());
			}
			
		}, null);
			
		// 组播发信息
		Message mess = new Message();
		MultipleAddresses address = new MultipleAddresses();
		address.addAddress(MultipleAddresses.TO, "hexiaogang@ts.local", null, null, false, null);
		address.addAddress(MultipleAddresses.CC, "xiaojinghai@ts.local", null, null, false, null);
		address.addAddress(MultipleAddresses.BCC, "luocanfeng@ts.local", null, null, false, null);
		mess.addExtension(address);
		mess.setBody("hello!");
		mess.setTo("multicast.ts.local");
		mess.setFrom("admin@ts.local");
		conn.sendPacket(mess);
		
		Thread.currentThread().suspend();
	}

}
